package com.example.fqapp.application;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import com.example.fqapp.room.dao.DaoUser;
import com.example.fqapp.room.database.FqDatabase;
import com.example.fqapp.service.MQTTManager;

import timber.log.Timber;

//自定义Application类是一种常见的做法，它允许你在整个应用中共享全局变量、配置全局的上下文环境、初始化一些需要在应用启动时进行的配置等。
public class MyApplication extends Application {
    public MQTTManager mqttManager = null;
    private Context context = null;
    public String tempString = "aaaaaaaaaa";
    public static MyApplication instance = null;
    public FqDatabase fqDatabase = null;

    @Override
    public void onCreate() {
        super.onCreate();

        instance = this;
        context = getApplicationContext();
        Log.d("MyApplication", "create, enter");
        // 在这里初始化你的应用
        // 初始化 Timber，添加一个 DebugTree 以输出到 Logcat
        Timber.plant(new Timber.DebugTree());
        mqttManager = new MQTTManager(context);

        //初使化数据库
        fqDatabase = Room.databaseBuilder(MyApplication.instance.getApplicationContext(), FqDatabase.class, "fqDatabase.db")
                .addMigrations(FqDatabase.MIGRATION_1_2) // 添加迁移规则
                .build();
    }
}
